//
//  JMMyWalletTVController.m
//  jiMuOperate
//
//  Created by 胡梅方 on 16/4/29.
//  Copyright © 2016年 jinXinFengLi. All rights reserved.
//

#import "JMMyWalletTVController.h"
#import "JMTableVController.h"
#import "JMWithdrawalsTVController.h"
@interface JMMyWalletTVController ()

@end

@implementation JMMyWalletTVController

- (void)viewDidLoad {
    [super viewDidLoad];
    self.tableView.scrollEnabled = NO;
     self.tableView.separatorStyle = UITableViewCellSeparatorStyleNone;
    UIView *view = [[UIView alloc]initWithFrame:CGRectMake(0, 0, SCREEN_WIDTH, 10)];
    self.tableView.tableHeaderView = view;
    self.tableView.backgroundColor = BACKCOLOR;
    self.navigationItem.title = @"我的钱包";
  }


- (NSInteger)tableView:(UITableView *)tableView numberOfRowsInSection:(NSInteger)section {

    return 3;
}


- (UITableViewCell *)tableView:(UITableView *)tableView cellForRowAtIndexPath:(NSIndexPath *)indexPath {
    static NSString *myWalletCell = @"myWalletCell";
    UITableViewCell *cell = [tableView dequeueReusableCellWithIdentifier:myWalletCell];
    if (!cell) {
        cell = [[UITableViewCell alloc]initWithStyle:UITableViewCellStyleDefault reuseIdentifier:myWalletCell];
    }
    CGFloat imageH = 40;
    CGFloat BtnH = 25;
    UIImageView *describImg = [[UIImageView alloc]initWithFrame:CGRectMake(10, 15, imageH/2, imageH/2)];
    describImg.frame = [ToolViewAndData MyAutoLayout:describImg];
    UILabel *descibLabel = [[UILabel alloc]initWithFrame:CGRectMake(imageH, 5, imageH*2, imageH)];
    UIButton *cellBtn = [ARC createButtonWithFrame:CGRectMake(255,BtnH/2, BtnH*2, BtnH) Target:self Sel:@selector(cellBtnClick:)];
    cellBtn.tag = indexPath.row + BtnTag;
    [cellBtn setTitle:@"降级" forState:UIControlStateNormal];
    [cellBtn setTitleColor:[UIColor whiteColor] forState:UIControlStateNormal];
    [cell.contentView addSubview:cellBtn];
    cellBtn.frame = [ToolViewAndData MyAutoLayout:cellBtn];
    descibLabel.textColor = [UIColor blackColor];
    [cell.contentView addSubview:descibLabel];
    [cell.contentView addSubview:describImg];
    
    UILabel *bangLab = [[UILabel alloc]initWithFrame:CGRectMake(120, 5, 100, imageH)];
    bangLab.frame = [ToolViewAndData MyAutoLayout:bangLab];
    bangLab.font =[UIFont systemFontOfSize:13];
    bangLab.textColor = [UIColor redColor];
    [cell.contentView addSubview:bangLab];
    UILabel *numLab = [[UILabel alloc]init];
    self.bindingNum = numLab;
    [bangLab addSubview:numLab];
    
    switch (indexPath.row) {
        case 0:
            describImg.image = [UIImage imageNamed:@"green_pine_cones"];
            descibLabel.text = @"绿松果";
            [cellBtn setBackgroundImage:[UIImage imageNamed:@"demotion_button"] forState:UIControlStateNormal];
            bangLab.text = [NSString stringWithFormat:@"可用:%@个",numLab.text];
            break;
        case 1:
            describImg.image = [UIImage imageNamed:@"red_pine_cones"];
            descibLabel.text = @"红松果";
            [cellBtn setBackgroundImage:[UIImage imageNamed:@"demotion_button"] forState:UIControlStateNormal];
              bangLab.text = [NSString stringWithFormat:@"未绑定:%@个",numLab.text];
            break;
        case 2:{
            describImg.image = [UIImage imageNamed:@"pine_nut"];
            descibLabel.text = @"松子";
            [cellBtn setBackgroundImage:[UIImage imageNamed:@"withdraw_deposit_button"] forState:UIControlStateNormal];
             [cellBtn setTitle:@"提现" forState:UIControlStateNormal];
            UIButton *rechargeBtn = [ARC createButtonWithFrame:CGRectMake(195, BtnH/2, BtnH*2, BtnH) Target:self Sel:@selector(cellBtnClick:)];
            rechargeBtn.tag = BtnTag+3;
            [cell.contentView addSubview:rechargeBtn];
            rechargeBtn.frame = [ToolViewAndData MyAutoLayout:rechargeBtn];
             [rechargeBtn setBackgroundImage:[UIImage imageNamed:@"top_up_button"] forState:UIControlStateNormal];
              [rechargeBtn setTitle:@"充值" forState:UIControlStateNormal];
            break;
        }
            
        default:
            break;
    }
    
    [cell.contentView addSubview:[ARC createImageViewLineWithHeigt:1]];
    return cell;

}
-(CGFloat)tableView:(UITableView *)tableView heightForRowAtIndexPath:(NSIndexPath *)indexPath
{
    return CELLHIGHT;
}
-(void)cellBtnClick:(UIButton*)btn
{
    NSLog(@"%d",btn.tag);
    switch (btn.tag-BtnTag) {
        case RedDowngradeBtn:{
            JMTableVController *tv = [[JMTableVController alloc]init];
            [self.navigationController pushViewController:tv animated:YES];
            break;
        }
        case GreenDowngradeBtn:{
            JMTableVController *tv = [[JMTableVController alloc]init];
            [self.navigationController pushViewController:tv animated:YES];
            break;
        }
        case WithdrawalsBtn:{
            JMWithdrawalsTVController *withdrawalTv = [[JMWithdrawalsTVController alloc]init];
            [self.navigationController pushViewController:withdrawalTv animated:YES];
            break;
        }
        case RechargeBtn:{
            JMTableVController *tv = [[JMTableVController alloc]init];
            [self.navigationController pushViewController:tv animated:YES];
            break;
        }

            
        default:
            break;
    }
}

@end
